<template>
  <div class="body">
    <div class="title">居民管理</div>
    <div class="inquire">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="楼栋ID">
          <el-select
            v-model="formInline.region"
            placeholder="请选择"
            class="id"
          >
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input
            v-model="formInline.user"
            placeholder="居民姓名"
            class="name"
          ></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input
            v-model="formInline.user"
            placeholder="居民电话"
            class="phone"
          ></el-input>
        </el-form-item>
        <el-form-item label="房间号">
          <el-input
            v-model="formInline.user"
            placeholder="房间号"
            class="room"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-form-item label="住户类型">
            <el-select
              v-model="formInline.region"
              placeholder="请选择"
              class="type"
            >
              <el-option label="区域一" value="shanghai"></el-option>
              <el-option label="区域二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="fun">
      <el-button type="primary" @click="addShow(true)">添加</el-button>

      <el-button type="success">批量删除</el-button>
      <el-button type="danger">批量审核</el-button>
    </div>
    <el-table
      border
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="30"></el-table-column>

      <el-table-column prop="id" label="id" width="70"> </el-table-column>
      <el-table-column prop="photo" label="头像" width="80"> </el-table-column>
      <el-table-column prop="name" label="姓名" width="120"> </el-table-column>
      <el-table-column prop="usertypeName" label="业主类型" width="60">
      </el-table-column>
      <el-table-column prop="sex" label="性别" width="40"> </el-table-column>
      <el-table-column prop="cardid" label="身份证号"> </el-table-column>
      <el-table-column prop="mobile" label="手机号" width="120">
      </el-table-column>
      <el-table-column
        prop="usernative"
        label="籍贯"
        show-overflow-tooltip
        width="80"
      >
      </el-table-column>
      <el-table-column
        prop="nation"
        label="民族"
        show-overflow-tooltip
        width="70"
      >
      </el-table-column>
      <el-table-column
        prop="houseno"
        label="小区"
        show-overflow-tooltip
        width="80"
      >
      </el-table-column>
      <el-table-column
        prop="houseid"
        label="房间号"
        show-overflow-tooltip
        width="70"
      >
      </el-table-column>
      <el-table-column
        prop="stateName"
        label="审核状态"
        show-overflow-tooltip
        width="80"
      >
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip style="width: 10%">
        <template slot-scope="scope">
          <el-button type="success">修改</el-button>
          <el-button type="danger" @click="delrow(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
      
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="Inline.page"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="Inline.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="counts"
      >
      </el-pagination>
    </div>
  <NoticeDialog :titleFlag="titleFlag" :show="showDialog" :updateData="updateData" @close="addShow"/>
   
  </div>
</template>

<script>
import http from "../../utils/request";
import NoticeDialog from './NoticeDialog.vue'

export default {
  components:{
    NoticeDialog
  },
  data() {
    return {
      
      showDialog:false,
      titleFlag:false,
      updateData:{},
      formInline: {
        user: "",
        region: "",
      },
      Inline: {
        pageSize: 2,
        page: 1,
      },
      counts: 0,

      tableData: [],
      multipleSelection: [],
      

      counts: 0,

      tableData: [],
      multipleSelection: [],
    };
  },
  mounted() {
    this.searchlist(); 
  },
  methods: {
    /**
     * 显示 隐藏 操作->[添加 修改 关闭 取消 确定]
     * @param show boolean 显示隐藏
     * @param data OBJECT 修改时的数据
     * @param flag Number 控制列表渲染 
    */
   
    addShow(show,data,flag){
      this.showDialog = show

    },
    delrow(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          http.get("/api/userinfo/delete?id=" + id).then((res) => {
            console.log(res);
            console.log(id);
            if (res.errCode === 10000) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.searchlist();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    searchlist() {
      http
        .get("/api/userinfo/list", {
          params: {
            psize: this.Inline.pageSize,
            page: this.Inline.page,
          },
        })
        .then((res) => {
          console.log(res);
          console.log(this.Inline.page);
          if (res.errCode === 10000) {
            this.tableData = res.data.list;
            this.counts = res.data.counts;
          }
        });
    },

    searchlist() {
      http
        .get("/api/userinfo/list", {
          params: {
            pageSize: this.Inline.pageSize,
            pageCounts: this.Inline.page,
          },
        })
        .then((res) => {
          console.log(res);
          if (res.errCode === 10000) {
            this.tableData = res.data.list;
            this.counts = res.data.counts;
            console.log(res.data.counts);
          }
        });
    },
    onSubmit() {
      console.log("submit!");
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.Inline.pageSize = val;

      this.Inline.pageSize = val;

      this.searchlist();
    },
    handleCurrentChange(val) {
      this.Inline.page = val;
      this.searchlist();
    },

    
  },
};
</script>

<style lang="less" scoped>
.title {
  color: rgb(77, 119, 196);
  border-bottom: 1px solid #eeeeee;
  padding-bottom: 30px;
  margin-bottom: 30px;
}
.demo-form-inline {
  padding-left: 20px;
}
.id {
  width: 250px;
}
.name {
  width: 150px;
}
.phone {
  width: 225px;
}
.room {
  width: 150px;
}
.type {
  width: 160px;
}
.fun {
  padding-left: 20px;
  margin-bottom: 20px;
}
.el-table {
  margin-left: 20px;

  margin-right: 20px;
}
.block {
  text-align: center;
}
.left {
  padding-left: 10px;
  box-sizing: border-box;
  width: 50%;
}
.el-form {
  display: flex;
}
.photo {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  p {
    margin-left: 30px;
    margin-right: 50px;
  }
}
.avatar-uploader {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 80px;
  height: 80px;
}
.avatar-uploader:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.block {
  text-align: center;
}
</style>